package com.spddr.pmos.oauth2;

import java.lang.reflect.Method;
import java.util.List;

import javax.ws.rs.ForbiddenException;

import org.apache.cxf.interceptor.security.AbstractAuthorizingInInterceptor;
import org.apache.cxf.interceptor.security.AccessDeniedException;
import org.apache.cxf.message.Message;

public class AuthorizingInterceptor extends AbstractAuthorizingInInterceptor {

	@Override
	public void handleMessage(Message message) {
		try {
			super.handleMessage(message);
		} catch (AccessDeniedException ex) {
			throw new ForbiddenException(ex);
		}
	}

	@Override
	protected List<String> getExpectedRoles(Method method) {
		// TODO Auto-generated method stub
		return null;
	}

	// @Override
	// protected List<String> getExpectedRoles(Method method) {
	// Set<RoleType> roles = EnumSet.noneOf(RoleType.class);
	//
	// RequireRole required = AnnotationUtils.findAnnotation(method, RequireRole.class);
	// if (null != required)
	// roles.addAll(Arrays.asList(required.value()));
	// required = AnnotationUtils.findAnnotation(method.getDeclaringClass(), RequireRole.class);
	// if (null != required)
	// roles.addAll(Arrays.asList(required.value()));
	//
	// return Lists.transform(new ArrayList<RoleType>(roles), new Function<RoleType, String>() {
	// @Override
	// public String apply(RoleType input) {
	// return input.name();
	// }
	// });
	// }

	// @Override
	// protected boolean authorize(SecurityContext sc, Method method) {
	// return super.authorize(sc, method);
	// }
	//
	// private Set<PermissionType> getExpectedPermissions(Method method) {
	// Set<PermissionType> permissions = EnumSet.noneOf(PermissionType.class);
	//
	// permissions.addAll(Arrays.asList(method.getAnnotation(RequirePermission.class).value()));
	// permissions.addAll(Arrays.asList(method.getClass().getAnnotation(RequirePermission.class).value()));
	//
	// return permissions;
	// }
}
